/*
 * @(#) UlynlistTest.js
 *
 * <br> Copyright:  Copyright (c) 2017
 * <br>
 * <br> @author caijinhuang
 * <br> 2017-12-21 15:15:36
 */

import React from 'react';
import $ from 'jquery';
import 'art-template';
import '@share/ulynlist/ulynlist';
import '@share/ulynlist/ulynlist.table';
import '@share/ulynlist/ulynlist.pagebar';
import '@share/ulynlist-ext';
import {
    Panel,
} from '@share/shareui';


class UlynlistTest extends React.Component{

    baseUrl_  = "http://localhost/sharemeeting";
    constructor(){
        super();
    }

    componentDidMount(){
                let opts = {
                    basePath: "node_modules/@share/ulynlist-ext",
                    tableTpl:"share",
                    tableColumn:{
                        title:'ulynlist',
                        rememberCheckbox:true,
                        keyColumn:"",
                        columns:[
                            {field:'CHECKED',checkbox:'ID',className:"sortable",width:"40px",style:"width:40px;"},
                            {field:'NICKNAME',overflowview:'ellipsis',label:'姓名',className:"unSortable"},
                            {field:'SEX',overflowview:'normal',label:'性别',className:"sortable",tableTransFunc:function(value,item){
                                if(value === "1"){
                                    return '<span>男</span>'
                                }
                                if(value === "0"){
                                    return '<span>女</span>'
                                }
                            }},
                            {field:'CREATE_TIME',overflowview:'normal',label:'委托日期',className:"unSortable",dataType:'HY',trans: 'toDisDate',width:"120px"},
                            {field:'gssq',overflowview:'normal',label:'归属社区',className:"unSortable"},
                            {field:'dcdw',overflowview:'normal',label:'状态',className:"unSortable",
                                tableTransFunc:function(value,item){
                                    if(value === "01"){
                                        return '<span><i class="fa fa-clock-o"></i>待审核</span>'
                                    }
                                    if(value === "02"){
                                        return '<span class="text-success"><i class="fa fa-check-circle"></i>审核通过</span>'
                                    }
                                    if(value === "03"){
                                        return '<span class="text-danger"><i class="fa fa-times-circle"></i>审核不通过</span>'
                                    }
                                }
                            },
                            {field:'wczt',overflowview:'normal',label:'完成状态',className:"unSortable"},
                            {field: 'gssq', label: '操作', style: "text-align:left", className: "sortable",width:"120",
                                tableTransFunc:function(value,item){
                                    return '<a class="table_do_a btn_view toDetail" href="javascript:void(0)">查看</a>' +
                                           '<a class="table_do_a btn_del deleteItem" href="javascript:void(0)">删除</a>'
                                }
                            }
                        ],
                        rownumbers:false,
                    },
                    extra:{
                        linesPerPageEditable:true,
                        tableSize:'',/*默认值为default，配置值支持 sm*/
                        lineStyle:'lineSpace'/*默认值为default，配置值支持 lineSpace(各行变色)*/
                    },
                    usePageBar:true,
                    requestData:{listSql:"user",linesPerPage:5,currentPage:1},
                    customAjax:function(requestData,callback){
                        let baseUrl = 'http://localhost/sharemeeting/ulynlist?';
                        $.ajax({
                                   url: baseUrl
                                        + "listSql=" + requestData.listSql
                                        + "&linesPerPage=" + requestData.linesPerPage
                                        + "&currentPage=" + requestData.currentPage,
                                   type:"get",
                                   contentType:"application/json",
                                   dataType:"json",
                                   xhrFields: {
                                       withCredentials: true
                                   },
                                   success:function(result){
                                       if(result.state === false){
                                           alert("获取失败");
                                       }else{
                                           let data = {
                                               status  : true,
                                               data  : {
                                                   list: result.data.list,
                                                   currentPage: result.data.currentPage,
                                                   totalNum: result.data.totalNum,
                                                   linesPerPage: requestData.linesPerPage
                                               }
                                           }
                                           console.log(requestData.linesPerPage);
                                           callback(data);
                                       }
                                   },
                                   error:function(data){
                                       alert("网络错误，请重试");
                                   }
                               });
                    },
                    pageBarId: 'ulyn-pageBar-id',
                    pageBarTpl:"share"
                };
                $("#ulyn-table-id").ulynlist(opts);
    }

    render(){
        return (
            <div>
                <Panel>
                    <Panel.Body full={true}>
                        <div id="ulyn-table-id"/>
                        <div id="ulyn-pageBar-id"/>
                    </Panel.Body>
                </Panel>
            </div>
        );
    }

}

export default UlynlistTest

